<template>
  <div class="dl">
    <div>
      <h2>登录</h2>
      <span>账号：</span>
      <input type="text" placeholder="账号" v-model="user" /><br /><br />
      <span>密码：</span>
      <input type="text" placeholder="密码" v-model="password" />
      <button @click="yan">登录</button>
      <router-link :to="{ name: 'Loginzc',params:{id:this.$route.params.id} }" tag="button">注册</router-link>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "dl",
  data() {
    return {
      user: "",
      password: "",
    //   text:''
    };
  },
  methods: {
    yan() {
      if (this.text != "" && this.password != "") {
        this.ajax({
          method: "post",
          url: "/queryUser",
          data: {
            user: this.user,
            password: this.password,
          },
        })
          .then((res) => {
            // this.text=res.data;
            alert(res.data);
            if(res.data=="登录成功"){
                localStorage.user=res.data;
                this.$router.push({name:"Shang",params:{id:this.$route.params.id}})
            }
          })
        //   .catch((res) => {
            
        //   });
      } else {
        alert("内容不能为空");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.dl {
  width: 100%;
  //   text-align: center;
  padding-top: 50px;
  > div {
    margin: auto;
    text-align: center;
    width: 300px;
    border: 1px solid rgb(138, 134, 134);
    background-color: rgb(233, 233, 233);
    padding: 10px;
    > button {
      margin: 20px 19px;
      width: 100px;
      height: 40px;
      background-color: rgb(185, 185, 185);
    }
  }
}
</style>